package com.jwcao.common.cast;

import com.jwcao.common.cast.context.CastContext;
import com.jwcao.common.cast.operation.CastFlow;

/**
 * name: Cast description: TODO
 *
 * @author caojingwei date: 2023/3/24 11:27
 */
public class Cast {

    public static final String DEFAULT_ID = "";

    public static <T, R> R get(T sourceObject, Class<R> targetClass) {
        CastFlow castFlow = CastContext.getCast(sourceObject, targetClass, DEFAULT_ID);
        return (R) castFlow.execute(sourceObject);
    }

    public static <T, R> R get(T sourceObject, Class<R> targetClass, String id) {
        CastFlow castFlow = CastContext.getCast(sourceObject, targetClass, id);
        return (R) castFlow.execute(sourceObject);
    }
}
